package hu;

import java.util.Scanner;

public class dzx2 {
    public static void main(String[] args) {
        Scanner sc = new Scanner(System.in);
        int m = sc.nextInt();
        int n = sc.nextInt();
        int[][] seat = new int[m][n];
        for (int i = 0; i < m; i++) {
            for (int j = 0; j < n; j++) {
                seat[i][j] = sc.nextInt();
            }
        }

        int ans = 0;
        for (int i = 0; i < m; i++) {
            for (int j = 0; j < n; j++) {
                if(seat[i][j] == 0){
                    ans = Math.max(ans, dfs(seat, i, j, 0));
                }

            }
        }
        System.out.println(ans);
    }
    public static int dfs(int[][] seat, int i, int j, int s){
        if(i < 0 || j < 0 || i >= seat.length || j >= seat[0].length || seat[i][j] == 1)
            return s;
        if((i - 1 < 0 || seat[i - 1][j] == 0) && (j - 1 < 0 || seat[i][j - 1] == 0) &&
                (i + 1 >= seat.length || seat[i + 1][j] == 0) && (j + 1 >= seat[0].length || seat[i][j + 1] == 0)){
            seat[i][j] = 1;
            int s1 = dfs(seat, i + 1, j, s + 1);
            int s2 = dfs(seat, i - 1, j, s + 1);
            int s3 = dfs(seat, i, j + 1, s + 1);
            int s4 = dfs(seat, i, j - 1, s + 1);
            seat[i][j] = 0;
            s = Math.max(s1,Math.max(s2, Math.max(s3,s4)));
        }
        else {
            int s1 = dfs(seat, i + 1, j, s);
            int s2 = dfs(seat, i - 1, j, s);
            int s3 = dfs(seat, i, j + 1, s);
            int s4 = dfs(seat, i, j - 1, s);
            s = Math.max(s1,Math.max(s2, Math.max(s3,s4)));
        }
        return s;
    }
}
/*
4 6
1 0 0 0 0 1
0 0 0 0 0 0
0 1 0 0 0 1
0 0 0 0 0 0

7

2 4
1 0 0 0
0 0 0 1

2
 */